var requests = require('../../requests/request.js');
var utils = require('../../utils/util.js');
// advise.js
Page({
  data: {
      isSubmit: false,      //icon 是否正在提交
      isDisabled:false,     //允许提交一次
      session3rd:''
  },
  onLoad: function () {
    var that = this;
    wx.getStorage({
        key: '3rd_session',
        success: function(res) { 
            that.setData({
                session3rd:res.data
            })
        },
    })
  },
  //提交反馈信息
  formSubmit: function (e) {
      var val = e.detail.value;
      var session = this.data.session3rd;
      //判断是否非空
      if ( val.contact === '' || val.advise === '' ){
        utils.showModal('提示','提交信息不能为空哦',false)
      }else{
          this.setData({
              isSubmit: true
          })
          //提交信息
          requests.requestSubAdvise(
              {
                  session: session,
                  opinion_detail:val.advise,
                  opinion_mobile: val.contact
              },(res) => {
                this.setData({
                    isSubmit: false,
                    isDisabled:true
                })
                if(res.state == 1){
                    utils.showModal('提示', '提交成功', false)
                }
              },() => {
                //请求失败
                this.setData({
                    isSubmit: false
                })
                utils.showModal('提示', '提交失败', false)
              },() => {
                //请求完成
                this.setData({
                    isSubmit: false
                })
              }
          )
      }
  },
})